package cn.wolfcode.luowowo2.mgrsite.web.controller;

import cn.wolfcode.luowowo2.article.domain.Strategy;
import cn.wolfcode.luowowo2.article.domain.StrategyCommend;
import cn.wolfcode.luowowo2.article.domain.StrategyDetail;
import cn.wolfcode.luowowo2.article.service.IStrategyCommendService;
import cn.wolfcode.luowowo2.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo2.article.service.IStrategyService;
import cn.wolfcode.luowowo2.common.query.StrategyCommendQueryObject;
import cn.wolfcode.luowowo2.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Albert on 2019/7/14.
 */
@Controller
@RequestMapping("strategyCommend")
public class StrategyCommendController {
    @Reference
    private IStrategyCommendService strategyCommendService;

    @Reference
    private IStrategyService strategyService;

    @Reference
    private IStrategyDetailService strategyDetailService;

    @RequestMapping("list")
    public String list(Model model,@ModelAttribute("qo") StrategyCommendQueryObject qo){
        PageInfo<StrategyCommend> pageInfo = strategyCommendService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        List<Strategy> strategies = strategyService.listAll();
        model.addAttribute("strategies",strategies);
        return "strategyCommend/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(StrategyCommend commend){
        strategyCommendService.saveOrUpdate(commend);
        AjaxResult ajaxResult = new AjaxResult();
        return ajaxResult;
    }

    @RequestMapping("getDetailByStrategyId")
    @ResponseBody
    public List<StrategyDetail> getDetailByStrategyId(Long strategyId){
        return strategyDetailService.getByStrateyId(strategyId);
    }
}
